Package org.apache.batik.test.svg
Class AbstractRenderingAccuracyTest
- java.lang.Object
-
- org.apache.batik.test.AbstractTest
-
- org.apache.batik.test.svg.AbstractRenderingAccuracyTest
-
- All Implemented Interfaces:
Test
- Direct Known Subclasses:
SVGRenderingAccuracyTest
public abstract class AbstractRenderingAccuracyTest extends AbstractTest
Checks for regressions in rendering a specific SVG document. TheTestwill rasterize and SVG document and compare it to a reference image. The test passes if the rasterized SVG and the reference image match exactly (i.e., all pixel values are the same).- Version:
- $Id: AbstractRenderingAccuracyTest.java 1808888 2017-09-19 14:22:11Z ssteiner $
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.FilecandidateReferenceThe File where the candidate reference should be saved if there is not candidate reference or if it cannot be opened.protected static java.util.ResourceBundleconfigurationThe configuration resource bundlestatic java.lang.StringCONFIGURATION_RESOURCESThe gui resources file namestatic java.lang.StringCOULD_NOT_GENERATE_COMPARISON_IMAGESMessages expressing that comparison images could not be created: {0} : exception class {1} : exception message {2} : exception stack trace.static java.lang.StringCOULD_NOT_LOAD_IMAGEMessages expressing that an image could not be loaded.static java.lang.StringCOULD_NOT_OPEN_VARIATION_URLMessage expressing that the variation URL could not be open {0} : URLstatic java.lang.StringENTRY_KEY_DIFFERENCE_IMAGEEntry describing the generated difference imagestatic java.lang.StringENTRY_KEY_ERROR_DESCRIPTIONEntry describing the errorstatic java.lang.StringENTRY_KEY_INTERNAL_ERROREntry describing that an internal error occured while generating the test failure descriptionstatic java.lang.StringENTRY_KEY_REFERENCE_GENERATED_IMAGE_URIEntry describing the reference/generated image filestatic java.lang.StringERROR_CANNOT_CREATE_TEMP_FILEError when temp file cannot be created {0} = IOException messagestatic java.lang.StringERROR_CANNOT_CREATE_TEMP_FILE_STREAMError when temp file stream cannot be created {0} = temp file's cannonical path {1} = IOException messagestatic java.lang.StringERROR_CANNOT_OPEN_GENERATED_IMAGEError when the generated image cannot be read {0} = Cannonical path of the temp generated image {1} = IOException messagestatic java.lang.StringERROR_CANNOT_OPEN_REFERENCE_IMAGEError when the reference image cannot be opened {0} = URI of the reference image {1} = IOException messagestatic java.lang.StringERROR_ERROR_WHILE_COMPARING_FILESError when there is an IOException while comparing the two reference raster image with the new raster image built from the SVG.static java.lang.StringERROR_SVG_RENDERING_NOT_ACCURATEError when the generated image from the SVG file differs from the reference image.static java.lang.StringIMAGE_FILE_EXTENSIONSuffix used for saved images (e.g., comparison and diff images)static java.lang.StringIMAGE_TYPE_COMPARISONSuffix used for comparison imagesstatic java.lang.StringIMAGE_TYPE_DIFFSuffix used for diff imagesprotected java.net.URLrefImgURLThe URL for the reference imageprotected java.io.FilesaveVariationThe File where the newly computed variation should be saved if different from the variationURLprotected java.net.URLsvgURLThe URL where the SVG can be found.static java.lang.StringTEMP_FILE_PREFIXPrefix for the temporary files created by Tests of this classstatic java.lang.StringTEMP_FILE_SUFFIXSuffix for the temporary files created by Tests of this classprotected static java.io.FiletempDirectoryTemporary directoryprotected java.util.ListvariationURLsA list ofURLs of files containing an 'accepted' variation from the reference image.-
Fields inherited from class org.apache.batik.test.AbstractTest
id, name, parent
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRenderingAccuracyTest()For subclassesAbstractRenderingAccuracyTest(java.lang.String svgURL, java.lang.String refImgURL)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddVariationURL(java.lang.String variationURL)Adds a URL for an acceptable variation from the reference image.static java.awt.image.BufferedImagebuildDiffImage(java.awt.image.BufferedImage ref, java.awt.image.BufferedImage gen)Builds a new BufferedImage that is the difference between the two input imagesprotected booleancompare(java.io.InputStream refStream, java.io.InputStream newStream)Compare the two input streamsabstract TestReportencode(java.net.URL srcURL, java.io.FileOutputStream fos)java.io.FilegetCandidateReference()protected java.awt.image.BufferedImagegetImage(java.io.File file)Loads an image from a Fileprotected java.awt.image.BufferedImagegetImage(java.net.URL url)Loads an image from a URLjava.lang.StringgetName()Returns thisTest's name.protected java.io.FilegetNextTempFileName(java.lang.String fileName)protected java.io.FilegetNextTempFileName(java.lang.String fileName, int instance)java.io.FilegetSaveVariation()static java.io.FilegetTempDirectory()Returns the temporary directoryprotected java.lang.StringgetURLFile(java.net.URL url)Extracts the file portion of the URLjava.lang.String[]getVariationURLs()protected java.io.FileimageToFile(java.awt.image.BufferedImage img, java.lang.String imageType)Creates a File into which the input image is saved.protected java.awt.image.BufferedImagemakeCompareImage(java.awt.image.BufferedImage ref, java.awt.image.BufferedImage gen)protected java.io.FilemakeRandomFileName(java.lang.String imageType)Creates a temporary File into which the input image is saved.protected java.io.FilemakeTempFileName(java.lang.String svgFileName, java.lang.String imageType)protected java.net.URLresolveURL(java.lang.String url)Resolves the input string as follows.TestReportrun()Requests thisTestto run and produce a report.protected voidsaveImage(java.awt.image.BufferedImage img, java.io.File imgFile)Saves an image in a given Fileprotected voidsaveImage(java.awt.image.BufferedImage img, java.io.OutputStream os)Saves an image in a given FilevoidsetCandidateReference(java.io.File candidateReference)voidsetConfig(java.lang.String svgURL, java.lang.String refImgURL)Sets this test's config.voidsetSaveVariation(java.io.File saveVariation)Sets the File where the variation from the reference image should be stored-
Methods inherited from class org.apache.batik.test.AbstractTest
assertEquals, assertEquals, assertNull, assertTrue, error, getId, getParent, getQualifiedId, reportError, reportException, reportSuccess, runImpl, runImplBasic, setId, setName, setParent
-
-
-
-
Field Detail
-
ERROR_CANNOT_CREATE_TEMP_FILE
public static final java.lang.String ERROR_CANNOT_CREATE_TEMP_FILE
Error when temp file cannot be created {0} = IOException message- See Also:
- Constant Field Values
-
ERROR_CANNOT_CREATE_TEMP_FILE_STREAM
public static final java.lang.String ERROR_CANNOT_CREATE_TEMP_FILE_STREAM
Error when temp file stream cannot be created {0} = temp file's cannonical path {1} = IOException message- See Also:
- Constant Field Values
-
ERROR_CANNOT_OPEN_REFERENCE_IMAGE
public static final java.lang.String ERROR_CANNOT_OPEN_REFERENCE_IMAGE
Error when the reference image cannot be opened {0} = URI of the reference image {1} = IOException message- See Also:
- Constant Field Values
-
ERROR_CANNOT_OPEN_GENERATED_IMAGE
public static final java.lang.String ERROR_CANNOT_OPEN_GENERATED_IMAGE
Error when the generated image cannot be read {0} = Cannonical path of the temp generated image {1} = IOException message- See Also:
- Constant Field Values
-
ERROR_ERROR_WHILE_COMPARING_FILES
public static final java.lang.String ERROR_ERROR_WHILE_COMPARING_FILES
Error when there is an IOException while comparing the two reference raster image with the new raster image built from the SVG. {0} = URI of the reference image {1} = Connical path for the temp generated image {2} = IOException message.- See Also:
- Constant Field Values
-
ERROR_SVG_RENDERING_NOT_ACCURATE
public static final java.lang.String ERROR_SVG_RENDERING_NOT_ACCURATE
Error when the generated image from the SVG file differs from the reference image.- See Also:
- Constant Field Values
-
ENTRY_KEY_ERROR_DESCRIPTION
public static final java.lang.String ENTRY_KEY_ERROR_DESCRIPTION
Entry describing the error- See Also:
- Constant Field Values
-
ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI
public static final java.lang.String ENTRY_KEY_REFERENCE_GENERATED_IMAGE_URI
Entry describing the reference/generated image file- See Also:
- Constant Field Values
-
ENTRY_KEY_DIFFERENCE_IMAGE
public static final java.lang.String ENTRY_KEY_DIFFERENCE_IMAGE
Entry describing the generated difference image- See Also:
- Constant Field Values
-
ENTRY_KEY_INTERNAL_ERROR
public static final java.lang.String ENTRY_KEY_INTERNAL_ERROR
Entry describing that an internal error occured while generating the test failure description- See Also:
- Constant Field Values
-
COULD_NOT_GENERATE_COMPARISON_IMAGES
public static final java.lang.String COULD_NOT_GENERATE_COMPARISON_IMAGES
Messages expressing that comparison images could not be created: {0} : exception class {1} : exception message {2} : exception stack trace.- See Also:
- Constant Field Values
-
COULD_NOT_LOAD_IMAGE
public static final java.lang.String COULD_NOT_LOAD_IMAGE
Messages expressing that an image could not be loaded. {0} : URL for the reference image.- See Also:
- Constant Field Values
-
COULD_NOT_OPEN_VARIATION_URL
public static final java.lang.String COULD_NOT_OPEN_VARIATION_URL
Message expressing that the variation URL could not be open {0} : URL- See Also:
- Constant Field Values
-
CONFIGURATION_RESOURCES
public static final java.lang.String CONFIGURATION_RESOURCES
The gui resources file name- See Also:
- Constant Field Values
-
IMAGE_TYPE_COMPARISON
public static final java.lang.String IMAGE_TYPE_COMPARISON
Suffix used for comparison images- See Also:
- Constant Field Values
-
IMAGE_TYPE_DIFF
public static final java.lang.String IMAGE_TYPE_DIFF
Suffix used for diff images- See Also:
- Constant Field Values
-
IMAGE_FILE_EXTENSION
public static final java.lang.String IMAGE_FILE_EXTENSION
Suffix used for saved images (e.g., comparison and diff images)- See Also:
- Constant Field Values
-
configuration
protected static java.util.ResourceBundle configuration
The configuration resource bundle
-
TEMP_FILE_PREFIX
public static final java.lang.String TEMP_FILE_PREFIX
Prefix for the temporary files created by Tests of this class
-
TEMP_FILE_SUFFIX
public static final java.lang.String TEMP_FILE_SUFFIX
Suffix for the temporary files created by Tests of this class
-
svgURL
protected java.net.URL svgURL
The URL where the SVG can be found.
-
refImgURL
protected java.net.URL refImgURL
The URL for the reference image
-
variationURLs
protected java.util.List variationURLs
A list ofURLs of files containing an 'accepted' variation from the reference image.
-
saveVariation
protected java.io.File saveVariation
The File where the newly computed variation should be saved if different from the variationURL
-
candidateReference
protected java.io.File candidateReference
The File where the candidate reference should be saved if there is not candidate reference or if it cannot be opened.
-
tempDirectory
protected static java.io.File tempDirectory
Temporary directory
-
-
Constructor Detail
-
AbstractRenderingAccuracyTest
public AbstractRenderingAccuracyTest(java.lang.String svgURL, java.lang.String refImgURL)Constructor.- Parameters:
svgURL- the URL String for the SVG document being tested.refImgURL- the URL for the reference image.
-
AbstractRenderingAccuracyTest
protected AbstractRenderingAccuracyTest()
For subclasses
-
-
Method Detail
-
getTempDirectory
public static java.io.File getTempDirectory()
Returns the temporary directory
-
setConfig
public void setConfig(java.lang.String svgURL, java.lang.String refImgURL)Sets this test's config.
-
resolveURL
protected java.net.URL resolveURL(java.lang.String url)
Resolves the input string as follows. + First, the string is interpreted as a file description. If the file exists, then the file name is turned into a URL. + Otherwise, the string is supposed to be a URL. If it is an invalid URL, an IllegalArgumentException is thrown.
-
setSaveVariation
public void setSaveVariation(java.io.File saveVariation)
Sets the File where the variation from the reference image should be stored
-
getSaveVariation
public java.io.File getSaveVariation()
-
getVariationURLs
public java.lang.String[] getVariationURLs()
-
addVariationURL
public void addVariationURL(java.lang.String variationURL)
Adds a URL for an acceptable variation from the reference image.
-
setCandidateReference
public void setCandidateReference(java.io.File candidateReference)
-
getCandidateReference
public java.io.File getCandidateReference()
-
getName
public java.lang.String getName()
Returns thisTest's name. The name is the URL of the SVG being rendered.- Specified by:
getNamein interfaceTest- Overrides:
getNamein classAbstractTest
-
run
public TestReport run()
Requests thisTestto run and produce a report.- Specified by:
runin interfaceTest- Overrides:
runin classAbstractTest
-
encode
public abstract TestReport encode(java.net.URL srcURL, java.io.FileOutputStream fos)
-
compare
protected boolean compare(java.io.InputStream refStream, java.io.InputStream newStream) throws java.io.IOExceptionCompare the two input streams- Throws:
java.io.IOException
-
saveImage
protected void saveImage(java.awt.image.BufferedImage img, java.io.File imgFile) throws java.io.IOExceptionSaves an image in a given File- Throws:
java.io.IOException
-
saveImage
protected void saveImage(java.awt.image.BufferedImage img, java.io.OutputStream os) throws java.io.IOExceptionSaves an image in a given File- Throws:
java.io.IOException
-
buildDiffImage
public static java.awt.image.BufferedImage buildDiffImage(java.awt.image.BufferedImage ref, java.awt.image.BufferedImage gen)Builds a new BufferedImage that is the difference between the two input images
-
getImage
protected java.awt.image.BufferedImage getImage(java.io.File file) throws java.lang.ExceptionLoads an image from a File- Throws:
java.lang.Exception
-
getImage
protected java.awt.image.BufferedImage getImage(java.net.URL url) throws java.io.IOExceptionLoads an image from a URL- Throws:
java.io.IOException
-
makeCompareImage
protected java.awt.image.BufferedImage makeCompareImage(java.awt.image.BufferedImage ref, java.awt.image.BufferedImage gen)
-
imageToFile
protected java.io.File imageToFile(java.awt.image.BufferedImage img, java.lang.String imageType) throws java.io.IOExceptionCreates 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.- Throws:
java.io.IOException
-
getURLFile
protected java.lang.String getURLFile(java.net.URL url)
Extracts the file portion of the URL
-
makeTempFileName
protected java.io.File makeTempFileName(java.lang.String svgFileName, java.lang.String imageType)
-
getNextTempFileName
protected java.io.File getNextTempFileName(java.lang.String fileName)
-
getNextTempFileName
protected java.io.File getNextTempFileName(java.lang.String fileName, int instance)
-
makeRandomFileName
protected java.io.File makeRandomFileName(java.lang.String imageType) throws java.io.IOExceptionCreates a temporary File into which the input image is saved.- Throws:
java.io.IOException
-
-